package com.iretailer.report.influxdb.util;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.MessageFormat;

/**
 * @author xjwtt
 * @date 2018/8/7
 */
public class InfluxDBUtil {
    private volatile static InfluxDB influxDB = null;
    private static Logger log = LoggerFactory.getLogger(InfluxDBUtil.class);


    public static InfluxDB getInfluxDB(String url) {
        if (influxDB == null) {
            synchronized (InfluxDBUtil.class) {
                if (influxDB == null) {
                    influxDB = InfluxDBFactory.connect(url);
                    log.error("------ InfluxDBFactory.connect({})",url);
                    log.error("------ InfluxDBFactory.connect({}); ", url);
                }
            }
        }
        return influxDB;
    }

    public static String defaultRetentionPolicy(String version) {
        if (version.startsWith("0.")) {
            return "default";
        } else {
            return "autogen";
        }
    }
}
